//
//  BCFindPassView.m
//  BangcaiBuy
//
//  Created by lsy on 16/6/28.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCFindPassView.h"

@implementation BCFindPassView
- (instancetype)initWithFrame:(CGRect)frame backImage:(UIImage *)ima
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView:ima];
    }
    return self;
}

- (void)createView:(UIImage*)ima
{
    
    self.backgroundColor = [UIColor whiteColor];
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 270 *hx)];
    headView.backgroundColor = BangcaiBlue;
    UIImageView *imageView = [[UIImageView alloc] init];
    [headView addSubview:imageView];
    UILabel *phoneLab = [[UILabel alloc] init];
    UILabel *conLab = [[UILabel alloc] init];
    UILabel *passLab = [[UILabel alloc] init];
    UILabel *rePassLab = [[UILabel alloc] init];
    self.regBut = [UIButton buttonWithType:UIButtonTypeSystem];
    imageView.image = ima;
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.bottom.mas_equalTo(-30);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(105);
    }];
    UILabel *phoneLine = [[UILabel alloc] init];
    UILabel *conLine = [[UILabel alloc] init];
    UILabel *pssLine = [[UILabel alloc] init];
    UILabel *rePassLine =[[UILabel alloc] init];
    phoneLine.backgroundColor = [UIColor colorWithRed:0.878  green:0.878  blue:0.878 alpha:1];
    conLine.backgroundColor = [UIColor colorWithRed:0.878  green:0.878  blue:0.878 alpha:1];
    pssLine.backgroundColor = [UIColor colorWithRed:0.878  green:0.878  blue:0.878 alpha:1];
    rePassLine.backgroundColor =[UIColor colorWithRed:0.878  green:0.878  blue:0.878 alpha:1];
    phoneLab.userInteractionEnabled = YES;
    phoneLab.layer.borderColor = [[UIColor colorWithRed:204/255.0  green:204/255.0  blue:204/255.0 alpha:1] CGColor];
    phoneLab.backgroundColor = [UIColor clearColor];
    UIImageView *userImg = [[UIImageView alloc] init];
    userImg.image = [UIImage imageNamed:@"手机"];
    [phoneLab addSubview:userImg];
    self.phoneNum = [[UITextField alloc] init];
    self.phoneNum.placeholder = @"用户";
    [self.phoneNum setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.phoneNum setValue:[UIFont systemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
    [phoneLab addSubview:self.phoneNum];
    
    
    
    conLab.userInteractionEnabled = YES;
    conLab.layer.borderColor = [[UIColor colorWithRed:204/255.0  green:204/255.0  blue:204/255.0 alpha:1] CGColor];
    conLab.backgroundColor = [UIColor clearColor];
    UIImageView *pssImg = [[UIImageView alloc] init];
    pssImg.image = [UIImage imageNamed:@"验证码"];
    [conLab addSubview:pssImg];
    
    passLab.userInteractionEnabled = YES;
    passLab.layer.borderColor = [[UIColor colorWithRed:204/255.0  green:204/255.0  blue:204/255.0 alpha:1] CGColor];
    passLab.backgroundColor = [UIColor clearColor];
    UIImageView *repssImg = [[UIImageView alloc] init];
    repssImg.image = [UIImage imageNamed:@"密码"];
    [passLab addSubview:repssImg];
    rePassLab.userInteractionEnabled = YES;
    rePassLab.layer.borderColor = [[UIColor colorWithRed:204/255.0  green:204/255.0  blue:204/255.0 alpha:1] CGColor];
    rePassLab.backgroundColor = [UIColor clearColor];
    UIImageView *rerepssImg = [[UIImageView alloc] init];
    rerepssImg.image = [UIImage imageNamed:@"新密码"];
    [rePassLab addSubview:rerepssImg];

    self.confirm = [[UITextField alloc] init];
    self.confirm.placeholder = @"请输入验证码";
    self.confirm.secureTextEntry = YES;
    [self.confirm setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.confirm setValue:[UIFont systemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
    
    self.getConfirm = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.getConfirm setTitle:@"获取验证码" forState:UIControlStateNormal];
    self.getConfirm.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.getConfirm setTitleColor:BangcaiBlue forState:UIControlStateNormal];
    self.getConfirm.layer.borderColor = BangcaiBlue.CGColor;
    self.getConfirm.layer.cornerRadius = 14;
    self.getConfirm.layer.borderWidth = 1;
    [conLab addSubview:self.getConfirm];
    
    [conLab addSubview:self.confirm];
    
    self.pass = [[UITextField alloc] init];
    self.pass.placeholder = @"请输入密码";
    self.pass.secureTextEntry = YES;
    [self.pass setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.pass setValue:[UIFont systemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
    [passLab addSubview:self.pass];
    
    self.rePass = [[UITextField alloc] init];
    self.rePass.placeholder = @"请确认密码";
    self.rePass.secureTextEntry = YES;
    [self.rePass setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.rePass setValue:[UIFont systemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
    [rePassLab addSubview:self.rePass];

    
    self.regBut.layer.cornerRadius = 3;
    self.regBut.backgroundColor = BangcaiBlue;
    [self.regBut setTitle:@"确认" forState:UIControlStateNormal];
    
    [self.regBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.regBut.titleLabel.font = [UIFont systemFontOfSize:20];
    
    [self addSubview:headView];
    [self addSubview:phoneLab];
    [self addSubview:conLab];
    [self addSubview:passLab];
    [self addSubview:rePassLab];
    [self addSubview:self.regBut];
    [self addSubview:phoneLine];
    [self addSubview:conLine];
    [self addSubview:pssLine];
    [self addSubview:rePassLine];
    
    [phoneLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.height.mas_equalTo(50 * hx);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.top.mas_equalTo(310 * hx);
    }];
    
    [phoneLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(SCREEN_WIDTH - 24);
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(phoneLab.mas_bottom);
        
    }];
    [userImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.and.height.mas_equalTo(25 * hx);
        make.top.and.left.mas_equalTo(12 * wx);
    }];
    [self.phoneNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(phoneLab);
        make.top.and.right.bottom.mas_equalTo(0);
        make.left.mas_equalTo(50);
        
    }];
    
    [conLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.and.height.equalTo(phoneLab);
        make.top.mas_equalTo(390 * hx);
        
    }];
    [conLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(SCREEN_WIDTH - 24);
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(conLab.mas_bottom);
    }];
    [pssImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.and.height.mas_equalTo(25 * hx);
        make.top.and.left.mas_equalTo(12 * wx);
        
    }];
    
    [passLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.and.height.equalTo(phoneLab);
        make.top.mas_equalTo(470 * hx);
        
    }];
    [pssLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(SCREEN_WIDTH - 24);
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(passLab.mas_bottom);
    }];
    [repssImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.and.height.mas_equalTo(25 * hx);
        make.top.and.left.mas_equalTo(12 * wx);
        
    }];
    
    [rePassLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.and.height.equalTo(phoneLab);
        make.top.mas_equalTo(550 * hx);
        
    }];
    [rePassLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.width.mas_equalTo(SCREEN_WIDTH - 24);
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(rePassLab.mas_bottom);
    }];
    [rerepssImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.and.height.mas_equalTo(25 * hx);
        make.top.and.left.mas_equalTo(12 * wx);
        
    }];

    
    
    [self.confirm mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.equalTo(phoneLab);
        make.top.and.right.bottom.mas_equalTo(0);
        make.left.mas_equalTo(50);
        
    }];
    
    [self.getConfirm mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.bottom.mas_equalTo(conLine.mas_bottom).with.offset(-10);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(28);
        
    }];
    [self.regBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.height.equalTo(phoneLab);
        make.width.mas_equalTo(SCREEN_WIDTH - 20);
        make.top.mas_equalTo(620 * hx);
    }];
    [self.pass mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(phoneLab);
        make.top.and.right.bottom.mas_equalTo(0);
        make.left.mas_equalTo(50);
    }];
    
    [self.rePass mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.equalTo(phoneLab);
        make.top.and.right.bottom.mas_equalTo(0);
        make.left.mas_equalTo(50);

    }];
    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.phoneNum resignFirstResponder];
    [self.confirm resignFirstResponder];
    [self.pass resignFirstResponder];
    return YES;
}



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.phoneNum resignFirstResponder];
    [self.confirm resignFirstResponder];
    [self.pass resignFirstResponder];
}


@end
